package offer_test_20;

import java.util.Queue;

import java.util.LinkedList;

public class seven_StackWithTwoQueue<T> {
	private Queue<T> one = new LinkedList<T>();
	private Queue<T> two = new LinkedList<T>();

	public T pop() {
		T re = null;
		if (one.size() == 0 && two.size() == 0) {
			return null;
		}
		if (one.size() == 0) {
			while (two.size() > 0) {
				re = two.poll();
				if (two.size() != 0)
					one.add(re);
			}
		} else {
			while (one.size() > 0) {
				re = one.poll();
				if (one.size() != 0)
					two.add(re);
			}
		}
		return re;
	}

	public void push(T t) {
		one.add(t);
	}

	public void show() {
		while(one.size()!=0){
			T temp=one.poll();
			two.add(temp);
		}
		for(T t:two){
			System.out.print(t.toString()+"  ");
		}
	}
	public static void main(String[] args) {
		int[] temp={1,2,3,4,5,6,7,8,9};
		seven_StackWithTwoQueue<Integer>  stack=new seven_StackWithTwoQueue<>();
//		for(int i:temp){
//			stack.push(i);
//		}
		stack.push(1);
		stack.push(2);
		stack.push(3);
		stack.push(4);
		stack.show();
		stack.pop();
		stack.push(5);
		stack.push(6);
		System.out.println();
		stack.show();
		stack.pop();
		stack.pop();
		stack.pop();
		stack.pop();
		System.out.println();
		stack.show();
	}
}
